package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShopCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import org.springframework.web.bind.annotation.*;

/**
 * @Author by 孙有泽
 * @Date 2025/3/23 9:48
 * @Description
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api("购物车模块")
public class ShopCartController {

    @Autowired
    private ShopCartService shopCartService;

    /*
     * @author 孙有泽
     * @date 2025/3/23 9:54
     * @description 添加购物车
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shopCartService.add(shoppingCartDTO);
        return Result.success();
    }

    /*
     * @author 孙有泽
     * @date 2025/3/23 11:22
     * @description 查询购物车
     */
    @GetMapping("/list")
    @ApiOperation("查询购物车")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> list=shopCartService.list();
        return Result.success(list);
    }

    /*
     * @author 孙有泽
     * @date 2025/3/23 12:22
     * @description 清空购物车
     */
    @DeleteMapping("/clean")
    public Result clean(){
        shopCartService.clean();
        return Result.success();
    }


}
